package dao.Impl;

import commons.druidJdbcUtil;
import dao.UpdateUserDao;
import pojo.User;

import javax.xml.transform.Result;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UpdateUserDaoImpl implements UpdateUserDao {


    @Override
    public void updateUser(User user) {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            conn=druidJdbcUtil.getConnection();
            conn.setAutoCommit(false);
            ps=conn.prepareStatement("update users set username=?,usersex=?,phoneNum=?,qqNum=? where userid =?");
            ps.setString(1,user.getUsername());
            ps.setString(2,user.getUsersex());
            ps.setString(3,user.getPhoneNum());
            ps.setString(4,user.getQqNum());
            ps.setInt(5,user.getUserid());
            ps.execute();
            conn.commit();

        }catch (Exception e){
            e.printStackTrace();
            druidJdbcUtil.roolback(conn);
        }finally {
            druidJdbcUtil.closeResource(conn,ps);
        }
    }
}
